_Pragma("once");

#include <cstdint>

#include "LoopGroupInfo.h"
#include "ErrorCode.h"
#include "LoopStatus.h"
#include "HalUtility.h"
#include "AcDetector.h"

#include "ExtendDeviceType.h"



class LoopController;


/**
 * 外扩设备上每一个回路控制器作为一个从机回路控制器
 *
 * @author lizb
 */

class SlaveLoopController {
public:
    /**
     * 从机回路控制器
     */
    SlaveLoopController(const ExtendDeviceType& deviceType, std::uint32_t slaveIndex, const LoopGroupInfo& groupInfo, LoopController& parent);


    /***
    * 回路控制器实际的控制方法
    *
    * @param command
    * @return
    */
    void changeAllChannelStatusFunc(const LoopStatus* command, const LoopSize_t& length) ;

    /***
     * 回路控制器实际的控制方法
     *
     * @param status
     * @param loopNum 从0开始
     * @return
     */
    void changeSingleChannelStatusFunc(const int& loopIndex, const LoopStatus& status) ;


    bool updateInfomation(std::string& result);


    void buildCommandAndSavePhase(const std::string_view& phaseView);


    /*
         int compareTo(IExtendDevice o) {
            if (o == null) {
                return 1;
            }
            if (this.getExtendNum() > o.getExtendNum()) {
                return 1;
            } else if (this.getExtendNum() < o.getExtendNum()) {
                return -1;
            } else {
                if (o.getClass().equals(getClass())) {
                    SlaveLoopController compareSlave = (SlaveLoopController) o;
                    if (this.slaveIndex > compareSlave.slaveIndex) {
                        return 1;
                    } else if (slaveIndex < compareSlave.slaveIndex) {
                        return -1;
                    } else {
                        return 0;
                    }
                }
            }
            return 0;

        }
    */

//    SlaveLoopController(const SlaveLoopController&) = delete;
  //  SlaveLoopController(SlaveLoopController&&) = delete;


    const ExtendDeviceType& mdeviceType;
    const LoopGroupInfo mgroupInfo;
    LoopController& mparent;

    std::string mslaveCommandPrefix;
    std::uint32_t mslaveIndex;

    std::string mcommandBuilder;
};
